package com.haojg.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiController {

    @Resource
    ChatClient chatClient;

    @RequestMapping("chat.do")
    public ResponseEntity<String> chat(@RequestParam("msg") String msg) {
        System.out.println("问：msg=" + msg);
        String content = chatClient.prompt().user(msg).call().content();
        System.out.println("content = " + content);
        return ResponseEntity.ok(content);
    }

}
